package cn.edu.gsau.info.dao;


import cn.edu.gsau.info.models.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MenuMapper extends BaseMapper<Menu> {
    @Select("SELECT            \n" +
            "\tDISTINCT m.`permission`\n" +
            "FROM\n" +
            "\t`tbl_userrole` ur\n" +
            "\tLEFT JOIN `tbl_role` r ON ur.`roleId` = r.`id`\n" +
            "\tLEFT JOIN `tbl_rolemenu` rm ON ur.`roleId` = rm.`roleId`\n" +
            "\tLEFT JOIN `tbl_menu` m ON m.`id` = rm.`menuId`\n" +
            "WHERE \n" +
            "\tur.`userId` = #{id}\n" +
            "\tAND r.`status` = 0\n" +
            "\tAND m.`status` = 0")
    List<String> selectPermsByUserId(Long id);

    @Select("SELECT DISTINCT m.name,m.path\n" +
            "FROM tbl_rolemenu rm INNER JOIN tbl_menu m ON rm.`menuId` = m.`id` \n" +
            "INNER JOIN `tbl_role` r ON r.`id` = rm.`roleId` \n" +
            "INNER JOIN `tbl_userrole` ur ON ur.`roleId` = r.`id`\n" +
            "INNER JOIN `tbl_user` u ON u.`id` = ur.`userId`\n" +
            "WHERE u.`id` =  ${id} AND m.`shownav`=0")
    List<Menu> selectMenuByUserId(Long userId);
}